package com.woniuxy.woniuticket.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZYF
 * @Description:TODO
 * @date 2019/6/13
 * @Version 1.0
 */

public class PageUtil {

    //用户layui返回map以及分页处理
    public static Map page(List list,int limit,int page){
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",list.size());

        if(list.size() <= limit ){
            map.put("data",list);
            return map;
        }
        int end = 2;
        int start = (page-1)*limit;
        if(list.size() % limit == 0 ){
            end = page*limit;
        }else{
            if((page-1) == list.size()/limit){
                end = list.size()%limit +start;
            }else{
                end = page*limit;
            }
        }
        map.put("data",list.subList(start,end));
        return map;
    }
}
